package main

import (
	"fmt"
	"strings"
)

func printTypeAndValue(tt interface{}) {
	fmt.Printf("type: %T\tvalue: %v\n", tt, tt)
}

func main() {
	buf := "abc adc a1c a7c 452 12 4 aac aaa Abc Abc ABC aBC aBc abC"
	printTypeAndValue(buf)
	printTypeAndValue(buf[:15])
	fmt.Println(len(buf))
	// strings.HasPrefix(s string, prefix string) bool：判断字符串s是否以prefix开头
	fmt.Printf("HasPrefix --> %v: %v\n", "a", strings.HasPrefix(buf, "a"))

	// strings.HasSuffix(s string, suffix string) bool：判断字符串s是否以suffix结尾
	fmt.Printf("HasSuffix --> %v: %v\n", "a", strings.HasSuffix(buf, "a"))

	// strings.Index(s string, str string) int：判断str在s中首次出现的位置，如果没有出现，则返回-1
	fmt.Printf("Index --> %v: %v\n", "a", strings.Index(buf, "aaa"))

	// strings.LastIndex(s string, str string) int：判断str在s中最后出现的位置，如果没有出现，则返回-1
	fmt.Printf("LastIndex --> %v: %v\n", "a", strings.LastIndex(buf, "a"))

	// strings.Replace(str string, old string, new string, n int)：字符串替换
	buffed := strings.Replace(buf, "a", "b", -1)
	fmt.Printf("Replace: %v --> %v: %v\n", "a", "b", buffed)

	// strings.Count(str string, substr string)int：字符串计数
	fmt.Printf("Count --> %v: %v\n", "a", strings.Count(buf, "aa"))

	// strings.Repeat(str string, count int)string：重复count次str
	fmt.Printf("Repeat --> %v * %d: %v\n", "ls ", 2, strings.Repeat("ls ", 2))

	// strings.ToLower(str string)string：转为小写
	fmt.Printf("ToLower --> %v --> \n\t    %v\n", buf, strings.ToLower(buf))
	// strings.ToUpper(str string)string：转为大写
	fmt.Printf("ToUpper --> %v --> \n\t    %v\n", buf, strings.ToUpper(buf))
	fmt.Printf("ToTitle --> %v --> \n\t    %v\n", buf, strings.ToTitle(buf))

	// strings.TrimSpace(str string)：去掉字符串首尾空白字符
	// strings.Trim(str string, cut string)：去掉字符串首尾cut字符
	// strings.TrimLeft(str string, cut string)：去掉字符串首cut字符
	// strings.TrimRight(str string, cut string)：去掉字符串首cut字符

	// strings.Field(str string)：返回str空格分隔的所有子串的slice
	fmt.Printf("Fields --> %v\n", strings.Fields(buf))
	// strings.Split(str string, split string)：返回str split分隔的所有子串的slice
	result := strings.Split(buf, "a")
	fmt.Printf("Split --> %v\n", result)

	// strings.Join(s1 []string, sep string)：用sep把s1中的所有元素链接起来
	fmt.Printf("Join --> %v\n", strings.Join(result, ""))

	// strings.Itoa(i int)：把一个整数i转成字符串
	// fmt.Printf("Itoa --> %v\n", strings.Itoa(4))

	// strings.Atoi(str string)(int, error)：把一个字符串转成整数
	// fmt.Printf("Itoa --> %v\n", strings.Atoi(56))

	// 子串
	// func Contains(s, substr string) bool： 子串substr在s中，返回true
	fmt.Printf("Contains --> %v\n", strings.Contains(buf, "a"))
	// func ContainsAny(s, chars string) bool： chars中任何一个Unicode代码点在s中，返回true
	fmt.Printf("ContainsAny --> %v\n", strings.ContainsAny(buf, "db"))
	// func ContainsRune(s string, r rune) bool: Unicode代码点r在s中，返回true
	fmt.Printf("ContainsRune --> %v\n", strings.ContainsRune(buf, 'a'))
}
